<#include "../public/header.html">
    <div id="editdlg">
    </div>
    <div class="easyui-layout" style="width:100%;height:100%;">
        <div id="p" data-options="region:'west'" title="校区" style="width:20%;padding:10px">
            <ul id="tt" class="easyui-tree" data-options="url:'admin/department/combotree',method:'get',animate:true,onClick:tree_select"></ul>
        </div>
        <div data-options="region:'center'" title="班级列表">
            <div id="tb" style="padding:5px 5px; border-bottom: dashed #d2d2d2 1px;margin-bottom: 5px;">
                班级名称: <input class="easyui-textbox" style="width:110px" id="class_name">
                <a href="javascript://" class="easyui-linkbutton" iconCls="icon-search" onclick="search_but()">搜索</a>
            </div>
            <table id="list" class="easyui-datagrid" style="width:100%;height:100%"
                   sortName="id"
                   sortOrder="asc"
                   rownumbers="true"
                   pagination="true"
                   pagesize="50"
                   singleSelect="true"
                   data-options="url:'admin/class/listJson',toolbar:toolbar">
                <thead>
                <tr>
                    <th width="140" field="dep_name" align="center"  sortable="true">单位名称</th>
                    <th width="140" field="class_name"  align="center" sortable="true">班级名称</th>
                    <th width="100" field="teacher_name"  align="center" sortable="true">班主任</th>
                    <th width="140" field="teacher_phone"  align="center" sortable="true">班主任联系方式</th>
                    <th width="100" field="class_cadre_1"  align="center" sortable="true">班干部1</th>
                    <th width="120" field="cadre_tel_phone_1" align="center" sortable="true">班干部联系电话1</th>
                    <th width="100" field="class_cadre_2"  align="center" sortable="true">班干部2</th>
                    <th width="120" field="cadre_tel_phone_2"  align="center" sortable="true">班干部联系电话2</th>
                    <th width="100" field="class_cadre_3"  align="center" sortable="true">班干部3</th>
                    <th width="120" field="cadre_tel_phone_3"  align="center" sortable="true">班干部联系电话3</th>
                    <th width="140" field="create_time" align="center" sortable="true" data-options="formatter:function(value,row,index){
                         return formatDate(value);
                         } ">创建时间</th>
                </tr>
                </thead>
            </table>


        </div>
    </div>


    <script type="text/javascript">

        function formatDate(now)   {
            var date = new Date(now*1000);
            return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() +' '+ date.getHours()+':'+date.getMinutes();
        }

        var id ;
        var content;
        var dep_id;
        $(function(){
            $("#tb").prependTo(".datagrid-toolbar");
        })
        var toolbar = [{
            id:20101,
            disabled:"${((permission_button.p20101!) == 'true')? string('','true')}",
            text:'添加',
            iconCls:'icon-add',
            handler:function(){

                $("#editdlg").dialog({
                    title:"添加",
                    iconCls: 'icon-edit',
                    width: '100%',
                    height: '100%',
                    closed: false,
                    cache: false,
                    modal: true,
                    href:"admin/class/edit",
                    onLoad:function() {
                        $.messager.progress('close');
                        var d = new Date()
                        var vYear = d.getFullYear();
                        if(dep_id !== undefined){
                            $("#dep_id").combotree("setValue",dep_id);
                        }
                        $("#grade").combobox("setValue",vYear);
                        $('#class_num').numberspinner('setValue', 1);

                    },
                    buttons: [{
                        text: '取消',
                        iconCls:'icon-cancel',
                        handler: function () {
                            $('#editForm').form('clear');
                            $("#editdlg").dialog("close");
                        }
                    },{
                        text: '保存',
                        iconCls: 'icon-ok',
                        handler: function () {
                            $('#editForm').form('submit',{
                                url:"admin/class/save",
                                dataType:"json",
                                onSubmit:function(){
                                    $("#memo").text(content.html());

                                    return $(this).form('enableValidation').form('validate');
                                },
                                success:function(data){
                                    var data = eval('(' + data + ')');  // change the JSON string to javascript object

                                    alert(data.msg);
                                    if(data.success==1){
                                        $("#editdlg").dialog("close");
                                        $("#list").datagrid("reload");
                                    }
                                }
                            });
                        }
                    }]
                });
            }
        },{
            id:20102,
            disabled:"${((permission_button.p20102!) == 'true')? string('','true')}",
            text:'编缉',
            iconCls:'icon-edit',
            handler:function(){
                var note =  $("#list").datagrid("getSelected");
                if(note == null){
                    $.messager.show({
                        title:'提醒',
                        msg:'请选择要编缉的行',
                        showType:'fade',
                        style:{
                            right:'',
                            bottom:''
                        }
                    });
                    return;
                }

                $.messager.progress({
                    text:'数据加载中....',
                    interval:100
                });

               $("#editdlg").dialog({
                   title:"编缉",
                   iconCls: 'icon-edit',
                   width: '100%',
                   height: '100%',
                   closed: false,
                   cache: false,
                   modal: true,
                   href:"admin/class/edit?id="+note.id,
                   onLoad:function() {
                       $.messager.progress('close');
                   },
                   buttons: [{
                       text: '取消',
                       iconCls:'icon-cancel',
                       handler: function () {
                           $('#editForm').form('clear');
                           $("#editdlg").dialog("close");
                       }
                   },{
                       text: '保存',
                       iconCls: 'icon-ok',
                       handler: function () {
                           $('#editForm').form('submit',{
                               url:"admin/class/save",
                               onSubmit:function(){
                                   $("#memo").text(content.html());
                                   return $(this).form('enableValidation').form('validate');
                               },
                               success:function(data){
                                   var data = eval('(' + data + ')');  // change the JSON string to javascript object
                                   alert(data.msg);
                                   if(data.success==1){
                                       $("#editdlg").dialog("close");
                                       $("#list").datagrid("reload");
                                   }
                               }
                           });
                       }
                   }]
               });
            }
        }];

        function search_but(){
           $("#list").datagrid("reload",{class_name:$("#class_name").val()});
        }

        function tree_select(note){
            $("#list").datagrid("reload",{class_name:$("#class_name").val(),dep_id:note.id});
            dep_id = note.id;
        }
    </script>
    <#include "../public/footer.html">